package utils;


import android.annotation.SuppressLint;
import android.app.AppOpsManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.net.Uri;
import android.os.Build;
import android.provider.Settings;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationManagerCompat;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Set;

/**
 * Created by HaiyuKing
 * Used 判断是否开启消息通知，没有开启的话跳转到手机系统设置界面
 * 参考：https://blog.csdn.net/lidayingyy/article/details/81778894
 * https://www.jianshu.com/p/205bc87cac29
 * https://blog.csdn.net/yrmao9893/article/details/74607402/
 * https://www.meiwen.com.cn/subject/qcklpftx.html
 */
public class NotificationSetUtil {


    public static boolean notificationListenerEnable(Context context) {
        boolean enable = false;
        String packageName = context.getPackageName();
        String flat= Settings.Secure.getString(context.getContentResolver(),"enabled_notification_listeners");
        if (flat != null) {
            enable= flat.contains(packageName);
        }
        return enable;
    }

    public static boolean isNotificationListenerEnabled(Context context) {
        Set<String> packageNames = NotificationManagerCompat.getEnabledListenerPackages(context);
        if (packageNames.contains(context.getPackageName())) {
            return true;
        }
        return false;
    }


}

